local skel = fk.CreateSkill {
  name = "rmt__chongshu",
}

Fk:loadTranslationTable{
  ["rmt__chongshu"] = "宠殊",
  [":rmt__chongshu"] = "每名角色限一次，结束阶段，你可以令一名角色使用你武将牌上任意张牌，然后其摸牌和回复体力至其装备区牌数。",

  ["#rmt__chongshu-choose"] = "宠殊：你可以令一名角色使用任意张“点漪”牌，然后其将手牌和体力值调整至其装备数",
  ["#rmt__chongshu-use"] = "宠殊：你可以使用其中一张装备",

  ["$rmt__chongshu1"] = "亲卿爱卿，是以卿卿；我不卿卿，谁当卿卿？",
  ["$rmt__chongshu2"] = "君怀高天之志，妾当体夏夷之仪。",
}

skel:addEffect(fk.EventPhaseStart, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and player.phase == Player.Finish and
      table.find(player.room.alive_players, function (p)
        return not table.contains(player:getTableMark(skel.name), p.id) and
          table.find(player:getPile("rmt__dianyi"), function (id)
            local card = Fk:getCardById(id)
            return not p:prohibitUse(card) and not p:isProhibited(p, card)
          end) ~= nil
      end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function (p)
      return not table.contains(player:getTableMark(skel.name), p.id) and
        table.find(player:getPile("rmt__dianyi"), function (id)
          return p:canUseTo(Fk:getCardById(id), p)
        end) ~= nil
    end)
    local tos = room:askToChoosePlayers(player, { targets = targets, min_num = 1, max_num = 1, prompt = "#rmt__chongshu-choose", skill_name = skel.name})
    if #tos > 0 then
      event:setCostData(self, { tos = tos })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    room:addTableMark(player, skel.name, to.id)
    while not player.dead and not to.dead do
      local cards = player:getPile("rmt__dianyi")
      if #cards == 0 then break end
      local use = room:askToUseRealCard(to, {
        pattern = cards, skill_name = skel.name, cancelable = true, expand_pile = cards, prompt = "#rmt__chongshu-use",
        extra_data = {
          bypass_times = true,
          extraUse = true,
          expand_pile = cards,
        }
      })
      if use == nil then break end
    end
    if to.dead then return end
    if to:getHandcardNum() < #to:getCardIds("e") then
      to:drawCards(#to:getCardIds("e") - to:getHandcardNum(), skel.name)
      if to.dead then return end
    end
    if to.hp < math.min(#to:getCardIds("e"), to.maxHp) then
      room:recover({
        who = to,
        num = math.min(#to:getCardIds("e"), to.maxHp) - to.hp,
        recoverBy = player,
        skillName = skel.name,
      })
    end
  end,
})


return skel
